package vip.xiaonuo.supplier.modular.finance.accounttype.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.finance.accounttype.entity.SupplierAccountType;
import vip.xiaonuo.supplier.modular.finance.accounttype.param.SupplierAccountTypeAddParam;
import vip.xiaonuo.supplier.modular.finance.accounttype.param.SupplierAccountTypeEditParam;
import vip.xiaonuo.supplier.modular.finance.accounttype.param.SupplierAccountTypeIdParam;
import vip.xiaonuo.supplier.modular.finance.accounttype.param.SupplierAccountTypePageParam;
import vip.xiaonuo.supplier.modular.finance.accounttype.service.SupplierAccountTypeService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 账户类型控制器
 *
 * @author Mr.wu
 * @date  2025/03/17 17:12
 */
@Tag(name = "账户类型控制器")
@RestController
@Validated
public class SupplierAccountTypeController {

    @Resource
    private SupplierAccountTypeService supplierAccountTypeService;

    /**
     * 获取账户类型分页
     *
     * @author Mr.wu
     * @date  2025/03/17 17:12
     */
    @Operation(summary = "获取账户类型分页")
    @SaCheckPermission("/supplier/finance/accounttype/page")
    @GetMapping("/supplier/finance/accounttype/page")
    public CommonResult<Page<SupplierAccountType>> page(SupplierAccountTypePageParam supplierAccountTypePageParam) {
        return CommonResult.data(supplierAccountTypeService.page(supplierAccountTypePageParam));
    }

    /**
     * 添加账户类型
     *
     * @author Mr.wu
     * @date  2025/03/17 17:12
     */
    @Operation(summary = "添加账户类型")
    @CommonLog("添加账户类型")
    @SaCheckPermission("/supplier/finance/accounttype/add")
    @PostMapping("/supplier/finance/accounttype/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierAccountTypeAddParam supplierAccountTypeAddParam) {
        supplierAccountTypeService.add(supplierAccountTypeAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑账户类型
     *
     * @author Mr.wu
     * @date  2025/03/17 17:12
     */
    @Operation(summary = "编辑账户类型")
    @CommonLog("编辑账户类型")
    @SaCheckPermission("/supplier/finance/accounttype/edit")
    @PostMapping("/supplier/finance/accounttype/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierAccountTypeEditParam supplierAccountTypeEditParam) {
        supplierAccountTypeService.edit(supplierAccountTypeEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除账户类型
     *
     * @author Mr.wu
     * @date  2025/03/17 17:12
     */
    @Operation(summary = "删除账户类型")
    @CommonLog("删除账户类型")
    @SaCheckPermission("/supplier/finance/accounttype/delete")
    @PostMapping("/supplier/finance/accounttype/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierAccountTypeIdParam> supplierAccountTypeIdParamList) {
        supplierAccountTypeService.delete(supplierAccountTypeIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取账户类型详情
     *
     * @author Mr.wu
     * @date  2025/03/17 17:12
     */
    @Operation(summary = "获取账户类型详情")
    @SaCheckPermission("/supplier/finance/accounttype/detail")
    @GetMapping("/supplier/finance/accounttype/detail")
    public CommonResult<SupplierAccountType> detail(@Valid SupplierAccountTypeIdParam supplierAccountTypeIdParam) {
        return CommonResult.data(supplierAccountTypeService.detail(supplierAccountTypeIdParam));
    }
}
